﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace SpaceFight.Units.Steering
{
	class Flee : SteeringBehavior
	{
		private SteeringInfo.InfoType m_neededInfo = SteeringInfo.InfoType.MaxAcceleration|
		                                             SteeringInfo.InfoType.Target;
		
		public override void GetSteering(IUnit p_unit, SteeringOutput p_steeringOutput)
		{
			if(HasValidInput(p_steeringOutput, p_unit, m_neededInfo) == false)
			{
				return;
			}
			
			// get the direction
			p_steeringOutput.Linear = p_unit.Position - p_unit.SteeringInfo.Target.Position;
			
			// don't accelerate if there is no direction
			if(p_steeringOutput.Linear.LengthSquared() == 0) return;
			
			// fully accelerate
			p_steeringOutput.Linear.Normalize();
			p_steeringOutput.Linear *= p_unit.SteeringInfo.MaxAcceleration;
		}
	}
}
